package cn.zzzhy.spider;

import cn.zzzhy.client.Client;

/**
 * @author zzzhy
 * @since 16/2/27 下午4:00
 */
public class SpiderManager {

    private SpiderPool spiderPool;

    private DownloadPool downloadPool;

    public static FetchType fetchType;

    public static Client client = null;

    public SpiderManager(Client client1) {
        client = client1;
    }

    public enum FetchType{
        All,MV,IMAGE
    }

    public static void setFetchType(FetchType fetchType1) {
        fetchType = fetchType1;
    }

    /**
     * 抓取器入口
     * @param destURL 目标地址
     */
    public void start(String destURL) {
        if(!destURL.startsWith("http")){
            destURL= "http://".concat(destURL);
        }

        this.spiderPool = new SpiderPool(destURL);
        spiderPool.startFetchUrls();
        this.downloadPool = new DownloadPool();
        downloadPool.start();

    }

    public void stop() {
        spiderPool.stop();
        downloadPool.stop();
    }

    public void pause() {
        spiderPool.pause();
    }
}
